<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>${_title}</title>

    <!-- Bootstrap core CSS -->

    <link href="${_css}/bootstrap.min.css" rel="stylesheet">

    <link href="${_font}/css/font-awesome.min.css" rel="stylesheet">
    <link href="${_css}/animate.min.css" rel="stylesheet">

    <!-- Custom styling plus plugins -->
    <link href="${_css}/custom.css" rel="stylesheet">
    <link href="${_css}/icheck/flat/green.css" rel="stylesheet">


    <script src="${_js}/jquery.min.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->

</head>


<body style="background: #F7F7F7;">
<div class="">
	
	<div class="row">
		<div class="col-md-12 col-sm-12 col-xs-12">
			<div class="x_panel">
				<div class="x_title">
		            <h2>编辑banner</h2>
		                
		            <div class="clearfix"></div>
		        </div>
		        <div class="x_content">
		            <form action="/file/upload" id="uploadForm" class="dropzone" style="border: 1px solid #e5e5e5; height: 300px;">
		            	<input type="hidden" id="resources" value="<#if model?? && model.resourceId??>${model.resourceId}</#if>">
		            	<#if model?? && model.path??>
			            	<div class="dz-preview dz-processing dz-image-preview dz-success dz-complete"> 
								<div class="dz-image">
									<img src="${model.path}" style="height:126px;width:126px;" alt="">
								</div>
							</div>
						</#if>
		            </form>
		        </div>
		    </div>
		</div>
		</div>
	</div>
    <div class="row">
        <div class="col-md-12 col-sm-12 col-xs-12">
            <div class="x_panel">
                <div class="x_title">
                    <h2>banner设置</h2>
                    <div class="clearfix"></div>
                </div>
                <div class="x_content">
                    <form class="form-horizontal form-label-left" novalidate>
                    	 <input type="hidden" id="bannerId" value="<#if model.id?exists>${model.id}</#if>">
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="title">标题 <span class="required">*</span>
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input id="title" class="form-control col-md-7 col-xs-12"
                                value="<#if model.title?exists>${model.title}</#if>"
                                name="title" placeholder="输入title" required="required" type="text">
                            </div>
                        </div>
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="linkUrl">链接地址 <span class="required">*</span>
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input type="url" id="linkUrl" name="linkUrl" required="required" placeholder="www.linkurl.com" 
                                value="<#if model.linkUrl?exists>${model.linkUrl}</#if>"
                                class="form-control col-md-7 col-xs-12">
                            </div>
                        </div>
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="orderIndex">banner显示顺序 <span class="required">*</span>
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input id="orderIndex" class="form-control col-md-7 col-xs-12"
                                name="orderIndex" placeholder="输入banner显示顺序" required="required" type="text"
                                value="<#if model.orderIndex?exists>${model.orderIndex}</#if>"
                                onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" >
                            </div>
                        </div>
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12">上传终端<span class="required">*</span>
                            </label>
                            <div class="col-md-3 col-sm-3 col-xs-6">
								<select class="form-control" id="terminal">
									<option value="PC" <#if model.terminal=="PC">selected="selected"</#if>>PC</option>
									<option value="APP" <#if model.terminal=="APP">selected="selected"</#if>>APP</option>
									<option value="WX" <#if model.terminal=="WX">selected="selected"</#if>>WX</option>
								</select>
                            </div>
                            <label id="bannerTip" class="control-label col-md-3 col-sm-3 col-xs-12">
	                            <#if model.terminal=="PC">
	                            	PC端Banner建议尺寸：1920*730
	                            <#else>
	                            	${model.terminal}端Banner建议尺寸：750*480
	                            </#if>
                            </label>
                        </div>  
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12">图片规格<span class="required">*</span>
                            </label>
                            <div class="col-md-3 col-sm-3 col-xs-6">
								 <select class="form-control" id="specific">
									<option value="S" <#if model.specific_=="S">selected="selected"</#if>>小banner</option>
									<option value="B" <#if model.specific_=="B">selected="selected"</#if>>大banner</option>
								 </select>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
	</div>
   	<div class="row">
	<div class="col-md-12 col-sm-12 col-xs-12">
	    <div class="ln_solid"></div>
	    <div class="form-group">
	        <div class="col-md-12 col-md-offset-5">
	            <button type="button" onclick="javascript:history.go(-1)" class="btn btn-primary">返回前一页</button>
	            <button id="send" type="button" class="btn btn-success">确认设置</button>
	        </div>
	    </div>			
	</div>
	</div> 
</div>
    <script src="${_js}/bootstrap.min.js"></script>
    <!-- bootstrap progress js -->
	<script src="${_js}/progressbar/bootstrap-progressbar.min.js" type="text/javascript"></script>
	<script src="${_js}/nicescroll/jquery.nicescroll.min.js" type="text/javascript"></script>

    <!-- chart js -->
    <script src="${_js}/custom.js"></script>
    <!-- dropzone -->
    <script src="${_js}/dropzone/dropzone.js" type="text/javascript" ></script>
    <!-- PNotify -->
	<script src="${_js}/notify/pnotify.core.js" type="text/javascript"></script>
	<script src="${_js}/notify/pnotify.buttons.js" type="text/javascript"></script>
	<script src="${_js}/notify/pnotify.nonblock.js" type="text/javascript" ></script>
    <script type="text/javascript">
    	$("#terminal").change(function(){
    		if($("#terminal").find("option:selected").val() == "PC"){
    			$("#bannerTip").html($("#terminal").find("option:selected").val() +"端Banner建议尺寸：1920*730");
    		}else{
    			$("#bannerTip").html($("#terminal").find("option:selected").val()+"端Banner建议尺寸：750*480");
    		}
    	});
    	
		$(".btn-success").click(function(){
			var bannerId = $("#bannerId").val();
			var resourceId = $("#resources").val();
			var title = $.trim($("#title").val());
			var linkUrl = $.trim($("#linkUrl").val());
			var orderIndex = $.trim($("#orderIndex").val());
			var terminal = $("#terminal").find("option:selected").val();
			var specific = $("#specific").find("option:selected").val();
			if(bannerId == ""){
				alert("编辑失败！");
				return;
			}
			var info=JSON.stringify({
				id:bannerId,
				resourceId:resourceId,
				title:title,
				linkUrl:linkUrl,
				orderIndex:orderIndex,
				terminal:terminal,
				specific:specific
			});
			$.ajax({
	            type: 'POST',
	            dataType: 'JSON',
	            async:'false',
	            headers: {'Content-type': 'application/json;charset=UTF-8'},
	            url: '/admin/banner/save',
	            data:info,
	            success: function(result){
	       		  if(result.code==-1){
	            		new PNotify({
			            	title: '操作提示',
			            	text: '设置成功',
			            	delay: 3e3,
			            	type: 'success'
			        	});
			        	window.location.href="/admin/banner/list";
	       		  }else{
	       		  		if(result.code == 0){
			        		alert("请先登录！");
							top.location.href = "/admin/login";
			        	}else{
		            		new PNotify({
				            	title: '操作提示',
				            	text: result.msg,
				            	delay: 3e3,
				            	type: 'error'
				        	});   
			        	}    		  	
	       		  }
	            }
		    })		
		});

		$(".dropzone").on("sending", function(file, xhr, formData) {
			if($("#resources").val() != ""){
				new PNotify({
			    	title: '操作提示',
			    	text: '一个banner只能设置一张图片',
			    	delay: 3e3,
			    	type: 'error'
				});   
				return;
			}
		});

		$(".dropzone").dropzone({
			acceptedFiles:'.jpg',
		    init: function() {
		        this.on("complete", function(file) {
		        	window.result=file;
		        	if(file!=null){
			        	var result = JSON.parse(file.xhr.response);
			        	if(result.code == 0){
			        		alert("请先登录！");
							top.location.href = "/admin/login";
			        	}
			        	$("#resources").attr("value",result.entity);
		        	}
		        });
		    }
		});		
		
    </script>
    
</body>

</html>